package com.fifth.apartment.mapper;

import com.fifth.apartment.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.Set;

@Mapper
public interface UserMapper {

    @Select("select password from user where username = #{username} ")
    String selectUserPassword(String username);

    @Select("select * from user where account = #{account}")
    User selectAllUser(String account);

    @Select("select * from user where username = #{name}")
    @Results(
            {
                    @Result(id = true,column = "id",property = "id"),
                    @Result(
                            column = "id",
                            property ="roles",
                            javaType = Set.class,
                            many =@Many(select ="com.fifth.apartment.mapper.RoleMapper.queryRoleById")
                    )
            }
    )
    User selectUserByName(String name);

    @Select("select * from user where phone = #{phone}")
    @Results(
            {
                    @Result(id = true,column = "id",property = "id"),
                    @Result(
                            column = "id",
                            property ="roles",
                            javaType = Set.class,
                            many =@Many(select ="com.fifth.apartment.mapper.RoleMapper.queryRoleById")
                    )
            }
    )
    User selectUserByPhone(String phone);
}
